package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.constant.RedisConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Address;
import com.itheima.service.AddressService;
import com.itheima.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import redis.clients.jedis.JedisPool;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/*
地址相关
 */
@RestController
@RequestMapping("/map")
public class AddressController {

    //操作redis
    @Autowired
    private JedisPool jedisPool;
    //连接注册中心
    @Reference
    private AddressService addressService;



    //页面查询
    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {
        PageResult pageResult = addressService.pageQuery(
                queryPageBean.getCurrentPage(),
                queryPageBean.getPageSize(),
                queryPageBean.getQueryString());
        return pageResult;
    }





    //根据id查询
    @RequestMapping("/findById")
    public Result findById(Integer id) {
        Address address = null;
        try {
            address = addressService.findById(id);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "查询失败");
        }
        return new Result(true, "查询成功", address);
    }


    //查找全图
    @RequestMapping("/findAllmap")
    public List<String> findAllmap(){
        return addressService.findAllmap();
    }

    @RequestMapping("/findAllAddress")
    public Result findAllAddress() {

        try {
            List<Map<String,Object>> list = addressService.findAllAddress();
            return new Result(true, "",list);

        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"");
        }
    }
}